package com.shujia;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;

public class Demo04List {
    Jedis jedis;

    @Before
    // 在@Test注解方法之前会运行一次
    public void init() {
        jedis = new Jedis("master", 6379);
    }

    @Test
    public void push() {
        jedis.lpush("l1", "1", "2", "3", "4");
        jedis.rpush("l1", "5", "6", "7");
    }

    @Test
    public void lIndex(){
        System.out.println(jedis.lindex("l1",2));
    }

    @Test
    public void lRange() {
        for (String vals : jedis.lrange("l1", 0, -1)) {
            System.out.println(vals);
        }
    }

    @Test
    public void pop() {
        System.out.println(jedis.lpop("l1"));
        System.out.println(jedis.rpop("l1"));
    }

    @Test
    public void lLen(){
        System.out.println(jedis.llen("l1"));
    }


    @After
    // 在@Test注解方法之后会运行一次
    public void close() {
        jedis.close();
    }
}
